Skip to content

GH-153809: Untrack TaskObj from GC before calling unregister_task#154563

Merged
kumaraditya303 merged 4 commits into
python:mainfrom
sergey-miryanov:fix-taskobj-dealloc
Jul 25, 2026
Merged

GH-153809: Untrack TaskObj from GC before calling unregister_task#154563
kumaraditya303 merged 4 commits into
python:mainfrom
sergey-miryanov:fix-taskobj-dealloc

Conversation

@sergey-miryanov

@sergey-miryanov sergey-miryanov commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

@sergey-miryanov

Copy link
Copy Markdown
Contributor Author

Reproducer with public API:

import sys, gc, threading, asyncio
assert not sys._is_gil_enabled()

N, ITERS = 4, 6000
barrier = threading.Barrier(N)


def leftover():
    1/0

async def inner():
    try:
        return asyncio.create_task(leftover)
    except Exception as exc:
        # print(exc)
        pass


async def outer():
    for i in range(ITERS):
        await inner()
        gc.collect()

def worker():
    barrier.wait()
    asyncio.run(outer())
    
ts = [threading.Thread(target=worker) for _ in range(N)]
for t in ts: t.start()
for t in ts: t.join()

I'm not sure we have to add it since it has time to run.

@sergey-miryanov
sergey-miryanov marked this pull request as ready for review July 24, 2026 21:03
@sergey-miryanov

Copy link
Copy Markdown
Contributor Author

@kumaraditya303 Could you please take a look.

@sergey-miryanov sergey-miryanov added needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 24, 2026
@kumaraditya303
kumaraditya303 merged commit 5062427 into python:main Jul 25, 2026
57 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @sergey-miryanov for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jul 25, 2026

Copy link
Copy Markdown

GH-154665 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 25, 2026
@bedevere-app

bedevere-app Bot commented Jul 25, 2026

Copy link
Copy Markdown

GH-154666 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 25, 2026
kumaraditya303 pushed a commit that referenced this pull request Jul 25, 2026
…ask (GH-154563) (#154666)

GH-153809: Untrack TaskObj from GC before calling unregister_task (GH-154563)
(cherry picked from commit 5062427)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
kumaraditya303 pushed a commit that referenced this pull request Jul 25, 2026
…ask (GH-154563) (#154665)

GH-153809: Untrack TaskObj from GC before calling unregister_task (GH-154563)
(cherry picked from commit 5062427)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants